home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / QuickDraw / Out of This GWorld / draw.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  5.0 KB  |  274 lines  |  [TEXT/KAHL]

  1. #include "out.h"
  2.  
  3. void createColorScale()
  4. {
  5.     int i;
  6.     int x;
  7.     int down = true;
  8.     int    index = 8;
  9.  
  10.     PenSize( 14, 1 );
  11.     
  12.     for (x = -420; x < 420; x += 105)
  13.     {
  14.         for (i = 0; i < 30; i++)
  15.         {
  16.             setColor( index );
  17.             
  18.             if (down == true)
  19.                 drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) );
  20.             else
  21.                 drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) );
  22.             index++;
  23.         }
  24.         
  25.         down = 1 - down;
  26.     }
  27.     
  28.     down = false;
  29.     index = 8;
  30.  
  31.     for (x = 368; x > -472; x -= 105)
  32.     {
  33.         for (i = 0; i < 30; i++)
  34.         {
  35.             setColor( index );
  36.             
  37.             if (down == true)
  38.                 drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) );
  39.             else
  40.                 drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) );
  41.             index++;
  42.         }
  43.         
  44.         down = 1 - down;
  45.     }
  46. }
  47.  
  48. void createColorWheels()
  49. {
  50.     testTriangle( -400, 300 );
  51.     testTriangle( 400, 300 );
  52.     testTriangle( 400, -300 );
  53.     testTriangle( -400, -300 );
  54.     shadeWasher( 0, 0, 360, 80 );
  55. }
  56.  
  57. void createColorRings()
  58. {
  59.     shadeWasher( 0, 0, 500, 400 );
  60.     shadeWasher( 0, 0, 400, 300 );
  61.     shadeWasher( 0, 0, 300, 200 );
  62.     shadeWasher( 0, 0, 200, 100 );
  63. }
  64.  
  65. void createColorGears()
  66. {
  67.     shadeWasher( 150, 150, 300, 100 );
  68.     shadeWasher( -150, 150, 300, 100 );
  69.     shadeWasher( -150, -150, 300, 100 );
  70.     shadeWasher( 150, -150, 300, 100 );
  71. }
  72.  
  73. void createColorCurves()
  74. {
  75.     shadeWasher( 720, 720, 900, 0 );
  76.     shadeWasher( 720, -720, 900, 0 );
  77.     shadeWasher( -720, -720, 900, 0 );
  78.     shadeWasher( -720, 720, 900, 0 );
  79.     shadeWasher( 0, 0, 400, 0 );
  80. }
  81.  
  82. void createColorBalls()
  83. {
  84.     int x, y;
  85.  
  86.     for (x = -432; x <= 432; x += 108)
  87.         for (y = -432; y <= 432; y += 108)
  88.             shadeWasher( x, y, 60, 0 );
  89. }
  90.  
  91. void createColorWave()
  92. {
  93.     shadeSCurve( -300, 250, 210, 60, 9 );
  94.     shadeSCurve( 96, 250, 210, 60, 69 );
  95.     shadeSCurve( -300, 150, 210, 60, 129 );
  96.     shadeSCurve( 96, 150, 210, 60, 189 );
  97.     shadeSCurve( -300, 50, 210, 60, 9 );
  98.     shadeSCurve( 96, 50, 210, 60, 69 );
  99.     shadeSCurve( -300, -50, 210, 60, 129 );
  100.     shadeSCurve( 96, -50, 210, 60, 189 );
  101.     shadeSCurve( -300, -150, 210, 60, 9 );
  102.     shadeSCurve( 96, -150, 210, 60, 69 );
  103.     shadeSCurve( -300, -250, 210, 60, 129 );
  104.     shadeSCurve( 96, -250, 210, 60, 189 );
  105. }
  106.  
  107. void createColorText()
  108. {
  109.     Rect        rect;
  110.     PicHandle    thePict;
  111.     int            width, height;
  112.     
  113.     thePict = (PicHandle)GetResource( 'PICT', 129 );
  114.     
  115.     width = (**thePict).picFrame.right - (**thePict).picFrame.left;
  116.     height = (**thePict).picFrame.bottom - (**thePict).picFrame.top;
  117.  
  118.     SetRect( &rect, (WWIDTH - width) / 2, (WHEIGHT - height) / 2, 
  119.                     ((WWIDTH - width) / 2) + width, ((WHEIGHT - height) / 2 ) + height );
  120.  
  121.     DrawPicture( thePict, &rect );
  122.     ReleaseResource( thePict );
  123. }
  124.  
  125. drawColorSpheres()
  126. {
  127.     int rad;
  128.     int i;
  129.  
  130.     for (i = 9; i < 48; i++)
  131.     {
  132.         setColor( i );
  133.         rad = (48 - i) * 3;
  134.         drawCircle( (int)(i * 1.414), (int)(i * 1.414), rad );
  135.     }
  136. }
  137.  
  138. void testTriangle( x, y )
  139. int x, y;
  140. {
  141.     PenSize( 1, 1 );
  142.  
  143.     setColor( 7 );
  144.     drawCircle( x, y, 25 );
  145.  
  146.     setColor( 1 );
  147.     drawWasher( x, y, 25, 60, -30, 30 );
  148.     drawLine( x - 60, y + 40, x, y + 140 );
  149.     drawLine( x, y + 140, x + 60, y + 40 );
  150.     setColor( 2 );
  151.     drawWasher(x, y, 25, 60, 30, 90 );
  152.     setColor( 3 );
  153.     drawWasher(x, y, 25, 60, 90, 150 );
  154.     drawLine( x + 60, y + 40, x + 121, y - 70 );
  155.     drawLine( x + 121, y - 70, x, y - 70 );
  156.     setColor( 4 );
  157.     drawWasher( x, y, 25, 60, 150, 210 );
  158.     setColor( 5 );
  159.     drawWasher( x, y, 25, 60, 210, 270 );
  160.     drawLine( x - 60, y + 40, x - 121, y - 70 );
  161.     drawLine( x - 121, y - 70, x, y - 70 );
  162.     setColor( 6 );
  163.     drawWasher( x, y, 25, 60, 270, 330 );
  164. }
  165.  
  166. void shadeWasher( x, y, radout, radin )
  167. int x, y;
  168. int radout, radin;
  169. {
  170.     int ang;
  171.     int i = 8;
  172.     int radmid;
  173.  
  174.     radmid = radin + (radout - radin) / 2;
  175.     
  176.     for (ang = 0; ang < 360; ang += 3)
  177.     {
  178.         setColor( i );
  179.         drawWasher( x, y, radmid, radout, ang, ang + 3 );
  180.         i++;
  181.     }
  182.     
  183.     for (ang = 0; ang < 360; ang += 3)
  184.     {
  185.         setColor( i );
  186.         drawWasher( x, y, radin, radmid, ang, ang + 3 );
  187.         i++;
  188.     }
  189. }
  190.  
  191. shadeSCurve( x, y, radout, radin, index )
  192. int x, y;
  193. int radout, radin;
  194. int index;
  195. {
  196.     int ang;
  197.     
  198.     for (ang = 270; ang > 90; ang -= 6)
  199.     {
  200.         setColor( index );
  201.         drawWasher( x, y, 60, 210, ang, ang - 6 );
  202.         index++;
  203.     }
  204.  
  205.     for (ang = -90; ang < 90; ang += 6)
  206.     {
  207.         setColor( index );
  208.         drawWasher( x + 198, y, 60, 210, ang, ang + 6 );
  209.         index++;
  210.     }
  211. }
  212.  
  213. void translate( x, y )
  214. int *x, *y;
  215. {
  216.     int xx, yy;
  217.     
  218.     xx = *x / SCALE;
  219.     yy = *y / SCALE;
  220.     
  221.     *x = xx + (WWIDTH / 2);
  222.     *y = (-yy) + (WHEIGHT / 2);
  223. }
  224.  
  225. void scale( len )
  226. int *len;
  227. {
  228.     *len /= SCALE;
  229. }
  230.  
  231. void drawCircle( x, y, radius )
  232. int x, y;
  233. int radius;
  234. {
  235.     Rect     rect;
  236.     int        foo = 0;
  237.     
  238.     translate( &x, &y );
  239.     scale( &radius );
  240.  
  241.     SetRect( &rect, x - radius, y - radius, x + radius, y + radius );
  242.     PaintOval( &rect );
  243. }
  244.  
  245. void drawWasher( x, y, irad, orad, sang, eang )
  246. int x, y;
  247. int irad, orad;
  248. int sang, eang;
  249. {
  250.     int        width;
  251.     Rect    rect;
  252.     
  253.     translate( &x, &y );
  254.     scale( &irad );
  255.     scale( &orad );
  256.     
  257.     width = (orad - irad) / 2;
  258.     
  259.     PenSize( width, width );
  260.     SetRect( &rect, x - (irad + width), y - (irad + width),
  261.                     x + (irad + width), y + (irad + width) );
  262.                     
  263.     FrameArc( &rect, sang, eang - sang );
  264.     PenSize( 1, 1 );
  265. }
  266.  
  267. void drawLine( sx, sy, ex, ey )
  268. {    
  269.     translate( &sx, &sy );
  270.     translate( &ex, &ey );
  271.     
  272.     MoveTo( sx, sy );
  273.     LineTo( ex, ey );
  274. }